package com.ruitu.health_1.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.health_1.mvp.model.ArticleModel;
import com.ruitu.health_1.ui.ArticleDetailsActivity;
import com.ruitu.health_1.ui.ArticleListActivity;
import com.ruitu.router_module.Logg;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.article.Article;
import com.ruitu.router_module.bean.article.ArticleInfo;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class ArticlePresenter {

    public static class ArticleP extends BasePresenter<ArticleListActivity, ArticleModel.ArticleM> {
        public Disposable getArticleList(int page, int size) {
            return m.getArticleList(page, size)
                    .subscribe(new Consumer<BaseResult2<PageModel2<Article>>>() {
                        @Override
                        public void accept(BaseResult2<PageModel2<Article>> listBaseResult2) throws Exception {
                            if (listBaseResult2.isSuccess()) {
                                Logg.i(listBaseResult2.toString());
                            }
                            v.setData(listBaseResult2.getData());
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                            throwable.printStackTrace();
                            v.setError();
                        }
                    });
        }
    }

    public static class ArticleDetailsP extends BasePresenter<ArticleDetailsActivity, ArticleModel.ArticleDetailsM> {
        public Disposable articleInfo(String id) {
            return m.articleInfo(id)
                    .subscribe(new Consumer<BaseResult2<ArticleInfo>>() {
                        @Override
                        public void accept(BaseResult2<ArticleInfo> articleInfoBaseResult2) throws Exception {
                            if (articleInfoBaseResult2.isSuccess()) {
                                v.setData(articleInfoBaseResult2.getData());
                            }
                        }
                    }, new Consumer<Throwable>() {
                        @Override
                        public void accept(Throwable throwable) throws Exception {
                        }
                    });
        }
    }

}
